<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="工作号" prop="job_number">
        <el-input
          v-model="queryParams.job_number"
          placeholder="请输入工作号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="发票号" prop="company_code">
        <el-input
          v-model="queryParams.invoice_num"
          placeholder="请输入发票号"
          clearable
          size="small"
        />
      </el-form-item>
<!--      <el-form-item label="结算单位" prop="settlement_unit">-->
<!--        <el-input-->
<!--          v-model="queryParams.settlement_unit"-->
<!--          placeholder="请输入结算单位"-->
<!--          clearable-->
<!--          size="small"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="发票抬头" prop="invoice_header">
        <el-input
          v-model="queryParams.invoice_header"
          placeholder="请输入发票抬头"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="税号" prop="taxpayer">
        <el-input
          v-model="queryParams.taxpayer"
          placeholder="请输入税号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入电话"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="开户行" prop="bank">
        <el-input
          v-model="queryParams.bank"
          placeholder="请输入开户行"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="银行账号" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入银行账号"
          clearable
          size="small"
        />
      </el-form-item>
<!--      <el-form-item label="开票公司" prop="invoicing_company">-->
<!--        <el-input-->
<!--          v-model="queryParams.invoicing_company"-->
<!--          placeholder="请输入开票公司"-->
<!--          clearable-->
<!--          size="small"-->
<!--        />-->
<!--      </el-form-item>-->

      <el-form-item label="核销日期" prop="cancel_date">
        <el-date-picker
          v-model="queryParams.cancel_date"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="金额" prop="rmb_xe">
        <el-input
          type="number"
          v-model="queryParams.rmb_xe_start"
          placeholder="开始"
          size="small"
          style="width: 45%"
        />
        -
        <el-input
          type="number"
          v-model="queryParams.rmb_xe_end"
          placeholder="结束"
          size="small"
          style="width: 45%"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column type="selection" align="center" width="50" />
      <el-table-column prop="job_number" label="工作号" align="center" width="200">
        <template v-slot="scope">
          <span style="color: #20a0ff;cursor:pointer" @click="see(scope.row)">{{ scope.row.job_number }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="invoice_num" label="发票号" align="center" />
<!--      <el-table-column prop="settlement_unit" label="结算单位" align="center" />-->
      <el-table-column prop="invoice_header" label="发票抬头" align="center" />
      <el-table-column prop="taxpayer" label="纳税识别号" align="center" />
<!--      <el-table-column prop="address" label="地址" align="center" />-->
<!--      <el-table-column prop="telephone" label="电话" align="center" />-->
      <el-table-column prop="bank" label="开户行" align="center" />
      <el-table-column prop="account" label="银行账号" align="center" />
      <el-table-column prop="invoice_type" label="发票类型" align="center" >
      <template slot-scope="scope">
          <p v-if="scope.row.invoice_type == '1'">货运代理发票</p>
          <p v-if="scope.row.invoice_type != '1'">未知</p>
      </template>
      </el-table-column>
<!--      <el-table-column prop="invoicing_company" label="开票公司" align="center" />-->
<!--      <el-table-column prop="invoice_status" label="发票状态" align="center" >-->
<!--      <template slot-scope="scope">-->
<!--        <p v-if="scope.row.invoice_status == '1'">NEW</p>-->
<!--        <p v-if="scope.row.invoice_status != '1'">未知</p>-->
<!--      </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column prop="cancel_date" label="核销日期" align="center" />-->
<!--      <el-table-column prop="stream_num" label="流水号" align="center" />-->
      <el-table-column prop="rmb_xe" label="人民币小写" align="center"  />
<!--      <el-table-column prop="exchange_rate" label="汇率" align="center" />-->
<!--      <el-table-column prop="tax_rate" label="税率" align="center" />-->
<!--      <el-table-column label="详情" align="center" width="50">-->
<!--        <template v-slot="scope">-->
<!--          <span style="color: #20a0ff;cursor:pointer" @click="see(scope.row)">查看</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handleEdit(scope.row)"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDel(scope.row)"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="warning"
            @click="prints(scope.row)"
          >打印
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" />
    <!-- 新增/修改 -->
    <AddEdit :open.sync="open" :title="title" :form="form" @getList="getList" />
    <!-- 详情 -->
    <Detail :opens.sync="opens" :title="title" :form="form" @getList="getList" />
    <!-- 打印 -->
    <Print :open-one.sync="openOne" :id="id" />
  </div>
</template>
<script>
import { invoiceList,invoiceDel } from '@/api/settlement'
import AddEdit from './AddEdit'
import Detail from './Detail'
import Print from './Print'
export default {
  name: 'Index',
  components: {
    Print,
    AddEdit,
    Detail
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      open: false,
      opens: false,
      openOne: false,
      title: '',
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      form: {},
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10,
        expenses_type: undefined
      },
      show: false,
      ids: [],
      id: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      const that = this
      this.loading = true
      invoiceList(this.queryParams).then(response => {
        if (response.code === 10000) {
          that.list = response.data
          that.total = response.count
          that.loading = false
        }
      })
    },
    /** 编辑按钮操作 */
    see(row) {
      this.form = row
      this.opens = true
      this.title = '详情'
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.form = {}
      this.open = true
      this.title = '添加'
    },
    /** 编辑按钮操作 */
    handleEdit(row) {
      this.form = row
      this.open = true
      this.title = '编辑'
    },
    /** 删除按钮操作 */
    handleDel(row) {
      console.log(row)
      const that = this
      that.$confirm('是否要删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        that.loading = true
        invoiceDel({ id: row.id.toString() }).then(response => {
          that.loading = false
          if (response.code === 10000) {
            that.$message.success(response.message)
            that.getList()
          } else {
            that.$message.error(response.message)
          }
        })
      }).catch(() => {
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        page: 1,
        limit: 10,
        company_code: undefined,
        name_c: undefined
      }
      this.handleQuery()
    },
    /** 打印 */
    prints(row) {
      this.id = row.id
      this.openOne = true
    }
  }
}

</script>

